<template>
    <IDrawer v-model="defaultValue" :loading="loading" :width="860" title="添加客户">
        <Form :model="data" :label-width="100" :rules="ruleValidate" ref="formCreate">
            <FormItem label="客户名称" prop="name">
                <Input v-model="data.name"></Input>
            </FormItem>
            <FormItem label="联系方式" prop="phone">
                <Input v-model="data.phone"></Input>
            </FormItem>
            <FormItem label="联系人" prop="contacts">
                <Input v-model="data.contacts"></Input>
            </FormItem>
            <Select v-model="data.assure">
                <Option :value="0">账册企业</Option>
                <Option :value="1">电商企业</Option>
                <Option :value="2">物流企业</Option>
            </Select>
            <FormItem label="回调地址" prop="docking.callback">
                <Input v-model="data.docking.callback" disabled></Input>
            </FormItem>
            <FormItem label="备注" prop="remark">
                <Input v-model="data.remark" type="textarea" :rows="4"></Input>
            </FormItem>
        </Form>
        <div slot="footer">
            <Button type="primary" icon="ios-add" @click="submit('formCreate')">提交</Button>
            <Button type="warning" icon="md-log-out" @click="defaultValue = false">返回</Button>
        </div>
    </IDrawer>
</template>

<script>
    import IDrawer from "../../../components/content/drawer";
    import contentDrawer from "../../../mixins/contentDrawer";
    import iData from "./data"

    export default {
        name: "IUpdate",
        mixins: [contentDrawer, iData],
        components: {IDrawer},
        mounted(){
            this.getData();
        },
        methods: {
            getData(){
                this.loading = true;
                this.$http.get(`customer/index/${this.props.id}/edit`).then((res) => {
                    this.data = res
                    this.loading = false;
                }).finally(() => {
                    this.loading = false;
                });
            },
            submit(data){
                this.validate(data).then(() => {
                    this.loading = true;
                    this.$http.put(`customer/index/${this.props.id}`, this.data).then(() => {
                        this.loading = false;
                        this.defaultValue = false;
                    });
                });
            }
        }
    }
</script>

<style scoped>

</style>
